#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "device.h"
#include "console.h"
#include "lcd_attr.h"


const uint8_t self_check[] = {
	0x0, 0x2, 0x92, 0x92, 0xda, 0xb6, 0x92, 0x91, 0xa9, 0xc1, 0x81, 0x0,
	0x90, 0xdc, 0xb3, 0x98, 0x0, 0x24, 0xf4, 0x2d, 0xe6, 0x24, 0x34, 0x24,
	0x0, 0x0, 0xfc, 0x24, 0x26, 0x25, 0x24, 0x24, 0x24, 0xfc, 0x0, 0x0, 
	0x88, 0x68, 0xff, 0x48, 0x10, 0xa8, 0x24, 0xa3, 0x24, 0x28, 0x90, 0x10, 

	0x0, 0xfc, 0x44, 0x44, 0x44, 0xff, 0x44, 0x44, 0x44, 0x44, 0xfc, 0x0, 
	0x0, 0x0, 0x80, 0x80, 0x0, 0x0,
	0x0, 0x0, 0x80, 0x80, 0x0, 0x0,
	0x0, 0x0, 0x80, 0x80, 0x0, 0x0,


	0x0, 0x4, 0x2, 0x0, 0x0, 0x8, 0xf, 0x0, 0x0, 0x2, 0x4, 0x0, 
	0x4, 0xc, 0x4, 0x2, 0xa, 0x4, 0x3, 0x0, 0x7, 0x8, 0x8, 0xe,
	0x0, 0x0, 0xf, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0xf, 0x0, 0x0, 
	0x1, 0x0, 0xf, 0x0, 0x8, 0xb, 0x8, 0xb, 0xc, 0xb, 0x8, 0x8, 
	0x0, 0x0, 0x0, 0x0, 0x0, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 
	0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 
	0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 
};

static void command_lcd(int argc, const char **argv)
{
    uint8_t i;
    
    lcd_clrscr();
    lcd_disp_img(30, 18, 78, 12, (uint8_t *)self_check);
    for (i=0; i<5; i++) {
       lcd_backlight(0);
       mdelay(1000);
       lcd_backlight(1);
       mdelay(1000);
    }
    
    for (i=0; i<=100; i++) {
        lcd_set_attribute(LCD_ATTR_GRAY, (void *)i);
        mdelay(50);
    }
    for (i=100; i>0; i--) {
        lcd_set_attribute(LCD_ATTR_GRAY, (void *)i);
        mdelay(50);
    }    
    lcd_set_attribute(LCD_ATTR_GRAY, (void *)50);
    mdelay(1000);
    lcd_clrscr();
}

const command_t lcd_cmd __command_entry = {
    "lcd",
    command_lcd,
    "lcd -- LCD test"
};
